package cn.anquing.controller;

import cn.anquing.model.City;
import cn.anquing.service.CityService;
import cn.anquing.vo.Response;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.feilong.core.RegexPattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/6/27 0027.
 */
@Controller
@RequestMapping
public class CityController extends BaseController {

    @Autowired
    private CityService cityService;

    @RequestMapping("hello")
    @ResponseBody
    public City printCity(){
//        City city = cityService.selectOne(new EntityWrapper<City>().eq("id", 1));
        City city = cityService.selectById(1);
        return city;
    }

    @RequestMapping("cityList")
    @ResponseBody
    public Response cityList(@RequestParam(value="page",required = false,defaultValue = "1") Integer page,
                             @RequestParam(value="limit",required = false,defaultValue = "2")Integer limit){

        Page<City> pageObj = new Page<City>(page, limit);
        pageObj = cityService.selectPage(pageObj,new EntityWrapper<City>().orderBy("id",true));
        List<City> records = pageObj.getRecords();
        String s = RegexPattern.MOBILEPHONE;
        for (City city:records) {
            city.setName(city.getName()+"1");
        }

        return success(pageObj);

    }

    @RequestMapping("cityList2")
    @ResponseBody
    public Response cityList2(@RequestParam(value="page",required = false,defaultValue = "1") Integer page,
                             @RequestParam(value="limit",required = false,defaultValue = "2")Integer limit){

        Page<City> pageObj = new Page<City>(page, limit);
        pageObj = cityService.selectCityPage(pageObj);


        return success(pageObj);

    }



}
